package fr.vahren.dotastrat.model;

import java.util.List;

import org.json.simple.JSONObject;

import fr.vahren.dotastrat.game.D2SGame;
import fr.vahren.dotastrat.game.D2SGameState;
import fr.vahren.dotastrat.game.effect.D2SEffect;

public class D2SCreeps extends D2SUnit {

	private static final double CREEP_DAMAGE_GROWTH = .20;
	private static final int CREEP_BASE_DAMAGE = 4;
	private static final int CREEP_HEALTH_GROWTH = 1;
	private static final int CREEP_BASE_HEALTH = 53;
	private static final int MEGA_CREEP_BASE_HEALTH = 73;
	private final static int TURNS_TO_LEVELUP = 30;
	private static final int MEGA_CREEP_HEALTH_GROWTH = 2;
	private static final double MEGA_CREEP_DAMAGE_GROWTH = .4;
	private D2SCreepType type;
	private int currentHealth;
	private int maxHealth;
	private int currentMana;
	private int maxMana;
	private int armor;
	private int damage;
	private boolean megaCreep = false;

	public D2SCreeps(D2SCreepType type, int turn, boolean isMegaCreep) {
		this.type = type;
		id = D2SGame.id();
		if (type == D2SCreepType.DIRE) {
			side = D2SSide.DIRE;
		} else if (type == D2SCreepType.RADIANT) {
			side = D2SSide.RADIANT;
		} else {
			side = D2SSide.NEUTRAL;
		}
		initStats(turn);
		megaCreep = isMegaCreep;
	}

	private void initStats(int turn) {
		switch (type) {
		case DIRE:
		case RADIANT:
			if (!megaCreep) {
				maxHealth = CREEP_BASE_HEALTH + (turn / TURNS_TO_LEVELUP)
						* CREEP_HEALTH_GROWTH;
				damage = (int) (CREEP_BASE_DAMAGE + (turn / TURNS_TO_LEVELUP)
						* CREEP_DAMAGE_GROWTH);
			} else {
				maxHealth = MEGA_CREEP_BASE_HEALTH + (turn / TURNS_TO_LEVELUP)
						* MEGA_CREEP_HEALTH_GROWTH;
				damage = (int) (CREEP_BASE_DAMAGE + (turn / TURNS_TO_LEVELUP)
						* MEGA_CREEP_DAMAGE_GROWTH);

			}
			currentHealth = maxHealth;
			break;

		default:
			break;
		}
	}

	/**
	 * @return the type
	 */
	public D2SCreepType getType() {
		return type;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(D2SCreepType type) {
		this.type = type;
	}

	@Override
	public int getArmor() {
		return armor;
	}

	@Override
	public void removeHealth(int dmg) {
		// TODO Auto-generated method stub

	}

	@Override
	public void applyAttackDamage(D2SUnit target, boolean reduced, D2SUnit unit) {
		// TODO Auto-generated method stub

	}

	@Override
	public int getCurrentHealth() {
		return currentHealth;
	}

	@Override
	public int getMaxHealth() {
		return maxHealth;
	}

	@Override
	public int getCurrentMana() {
		return currentMana;
	}

	@Override
	public int getMaxMana() {
		return maxMana;
	}

	@Override
	public void addAttacker(int id) {
		// TODO Auto-generated method stub

	}

	@Override
	public int getSpeed() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<D2SEffect> getEffects() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public JSONObject generateInfo(D2SGameState phase) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getAttackRange() {
		return 1;
	}

	@Override
	public int getGoldBounty(int nbAttackers) {
		switch (type) {
		case RADIANT:
		case DIRE:
			return (megaCreep ? 25 : 50) / nbAttackers;
		case ANCIENT:
			return 260 / nbAttackers;
		case BIG:
			return 125 / nbAttackers;
		case MEDIUM:
			return 100 / nbAttackers;
		case SMALL:
			return 80 / nbAttackers;
		case ROSHAN:
			return 350 / nbAttackers;
		default:
			return 0;
		}
	}

	@Override
	public int getExpBounty(int size) {
		switch (type) {
		case RADIANT:
		case DIRE:
			return (megaCreep ? 20 : 45) / size;
		case ANCIENT:
			return 350 / size;
		case BIG:
			return 220 / size;
		case MEDIUM:
			return 200 / size;
		case SMALL:
			return 130 / size;
		case ROSHAN:
			return 1789 / size;
		default:
			return 0;
		}
	}

}
